﻿// 4. Write a method that counts how many times given number appears in given array. Write a test program to check if the
// method is working correctly.

using System;

class CountGivenNumberInArray
{
    static void Main()
    {
        Console.Write("Enter the number for search and count : ");
        double numberForCount = double.Parse(Console.ReadLine());

        Console.Write("Enter the length of the array : ");
        int length = int.Parse(Console.ReadLine());

        Console.WriteLine("Enter values for the array : ");
        double[] array = new double[length];
        for (int i = 0; i < length; i++)
        {
            Console.Write("array[{0}] = ", i);
            array[i] = double.Parse(Console.ReadLine());
        }

        int result = CountGivenNumber(numberForCount, array);

        Console.WriteLine("The enetered element {0} appears {1} times in the given array.", numberForCount, result);

    }

    static int CountGivenNumber(double number, double[] array)
    {
        int count = 0;

        for (int index = 0; index < array.Length; index++)
        {
            if (array[index] == number)
            {
                count++;
            }
        }

        return count;
    }
}
